package com.situ.ssh.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.situ.ssh.entity.Department;
import com.situ.ssh.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

@Controller
@Scope("prototype")
public class DepartmentAction extends ActionSupport implements ModelDriven<Department> {
    private Department department = new Department();

    @Autowired
    private IDepartmentService departmentService;

    public String list() {
        List<Department> list = departmentService.findAll();
        ActionContext actionContext = ActionContext.getContext();
        Map<String, Object> sessionMap = actionContext.getSession();
        sessionMap.put("list", list);
        return "list";
    }


    public Department getModel() {
        return department;
    }
}
